package cn.lhx.blog.dao;

import java.util.List;

import org.hibernate.Query;

import cn.lhx.blog.pojo.Comment;

public class DaoComment extends BasicDao {

	@Override
	public int delete(int id) {
		getHibernateTemplate().delete(getHibernateTemplate().get(Comment.class, id));
		return id;
	}

	@Override
	public List<?> executeQuery(String sql) {
		Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(sql);
		return query.list();
	}

	@Override
	public int executeUpdate(String sql) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object getById(int id) {
	     
		return getHibernateTemplate().get(Comment.class, id);
	}

	@Override
	public List<?> getList(int begin, int size) {
		Query query = getSessionFactory().getCurrentSession().createQuery(
				"from Comment comment order by comment.postTime desc");
		query.setFirstResult(begin);
		query.setMaxResults(size);
		return query.list();
	}

	@Override
	public Object insert(Object obj) {
		Comment comment = (Comment) obj;
		getHibernateTemplate().save(comment);
		return comment;
	}

	@Override
	public Object update(Object obj) {
		// TODO Auto-generated method stub
		return null;
	}

}
